﻿namespace Distributions
{
    using System;

    using Shared;

    public class PoissonDistribution : IDistribution
    {
        public double NextDouble()
        {
            throw new NotImplementedException();
        }

        public double NextDouble(int k, double mean)
        {
            // f(x) = e-λλx / x!
            double poisson = (Math.Pow(Math.E, -mean) * Math.Pow(mean, k)) / Factorial(k);

            return Math.Round(poisson, 15);
        }

        private static double Factorial(int x)
        {
            double factorial = 1;
            double i = 1;

            while (i <= x)
            {
                factorial = factorial * i;
                i++;
            }

            return factorial;
        }
    }
}
